package com.hhm.huo.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hhm.huo.entity.Result;
import com.hhm.huo.entity.Safe;
import com.hhm.huo.entity.Search;
import com.hhm.huo.service.ISafeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 安安
 * @since 2022-06-06
 */
@RestController
@RequestMapping("/safe")
public class SafeController {
    @Autowired
    ISafeService safeService;

    @RequestMapping("list")
    public Result list(@RequestBody Search search){
        QueryWrapper<Safe> wrapper = new QueryWrapper<>();
        // 查询
        if (StringUtils.hasText(search.getTbName())){
            wrapper.like("tb_name", search.getTbName());
        }
        if (StringUtils.hasText(search.getSyName())){
            wrapper.like("sy_name", search.getSyName());
        }
        if (StringUtils.hasText(search.getBbxName())){
            wrapper.like("bbx_name", search.getBbxName());
        }
        if (StringUtils.hasText(search.getType())){
            wrapper.eq("type", search.getType());
        }
        if (search.getStartbxMoney()>=0){
            wrapper.ge("bx_money", search.getStartbxMoney());
        }
        if (search.getEndbxMoney()>=0){
            wrapper.ge("bx_money", search.getEndbxMoney());
        }

        List<Safe> list = safeService.list(wrapper);
        return new Result(200, "", list);

    }

    /**
     * 批删
     * @param ids
     * @return
     */
    @RequestMapping("delBatch")
    public Result delBatch(String ids){
        // 切割
        String[] split = ids.split(",");
        for (String id : split) {
            safeService.removeById(id);
        }
        return new Result(200, "");

    }
}
